package com.jinzht.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.math.BigInteger;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;

public class FileUtil {
	public static boolean saveFile(String fileName, MultipartFile file,
			String filePath) {
		// 获取文件存储路径
		String path = System.getProperty("hengfengapp.root") + filePath;
		// 输出流
		OutputStream os;
		InputStream is;
		try {
			File f = new File(path);

			// 创建文件夹
			if (!f.exists()) {
				f.mkdirs();
			}

			os = new FileOutputStream(new File(path, fileName));
			// 输入流
			is = file.getInputStream();

			byte[] buf = new byte[1024];
			int length = 0;

			while (-1 != (length = is.read(buf))) {
				os.write(buf, 0, length);
			}

			is.close();
			os.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

		return true;
	}

	/***
	 * 保存文件
	 * 
	 * @param file
	 * @param fileName
	 */
	public static String savePicture(MultipartFile file, String fileName,
			String path) {
		String headerPicture = "";
		if (file != null && !file.isEmpty()) {
			// 定义一个数组，用于保存可上传的文件类型
			List fileTypes = new ArrayList();
			fileTypes.add("jpg");
			fileTypes.add("jpeg");
			fileTypes.add("bmp");
			fileTypes.add("gif");
			fileTypes.add("mp3");
			fileTypes.add("wav");

			// 获取上传文件类型的扩展名,先得到.的位置，再截取从.的下一个位置到文件的最后，最后得到扩展名
			String orignalFileName = file.getOriginalFilename();
			String ext = orignalFileName.substring(
					orignalFileName.lastIndexOf(".") + 1,
					orignalFileName.length());

			System.out.println("文件长度: " + file.getSize());
			System.out.println("文件类型: " + file.getContentType());
			System.out.println("文件名称: " + file.getName());
			System.out.println("文件原名: " + file.getOriginalFilename());
			System.out.println("========================================");

			// 保存
			fileName += "." + ext;
			if (saveFile(fileName, file, path)) {
				return fileName;
			}
			return "";
		}
		return "";
	}

	/***
	 * 保存Excel文件
	 * 
	 * @param file
	 * @param fileName
	 */
	public static String saveFile(MultipartFile file, String fileName,
			String path) {
		String headerPicture = "";
		if (file != null && !file.isEmpty()) {
			// 定义一个数组，用于保存可上传的文件类型
			List fileTypes = new ArrayList();
			fileTypes.add("xlsx");
			fileTypes.add("xls");

			// 获取上传文件类型的扩展名,先得到.的位置，再截取从.的下一个位置到文件的最后，最后得到扩展名
			String orignalFileName = file.getOriginalFilename();
			String ext = orignalFileName.substring(
					orignalFileName.lastIndexOf(".") + 1,
					orignalFileName.length());

			System.out.println("文件长度: " + file.getSize());
			System.out.println("文件类型: " + file.getContentType());
			System.out.println("文件名称: " + file.getName());
			System.out.println("文件原名: " + file.getOriginalFilename());
			System.out.println("========================================");

			// 保存
			fileName += "." + ext;
			if (saveFile(fileName, file, path)) {
				return fileName;
			}
			return "";
		}
		return "";
	}

	/**
	 * 以字节为单位读取文件，常用于读二进制文件，如图片、声音、影像等文件。
	 */
	public static String readFileByBytes(String fileName) {
		File file = new File(fileName);
		InputStream in = null;
		try {
			System.out.println("以字节为单位读取文件内容，一次读一个字节：");
			// 一次读一个字节
			in = new FileInputStream(file);
			int tempbyte;
			while ((tempbyte = in.read()) != -1) {
				System.out.write(tempbyte);
			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
		try {
			System.out.println("以字节为单位读取文件内容，一次读多个字节：");
			// 一次读多个字节
			byte[] tempbytes = new byte[1024];
			int byteread = 0;
			in = new FileInputStream(fileName);
			FileUtil.showAvailableBytes(in);
			// 读入多个字节到字节数组中，byteread为一次读入的字节数
			String str = "";
			while ((byteread = in.read(tempbytes)) != -1) {
				System.out.write(tempbytes, 0, byteread);
				str += new String(tempbytes);
			}

			return str;
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e1) {
				}
			}
		}

		return "";
	}

	/**
	 * 以字符为单位读取文件，常用于读文本，数字等类型的文件
	 */
	public static void readFileByChars(String fileName) {
		File file = new File(fileName);
		Reader reader = null;
		try {
			System.out.println("以字符为单位读取文件内容，一次读一个字节：");
			// 一次读一个字符
			reader = new InputStreamReader(new FileInputStream(file));
			int tempchar;
			while ((tempchar = reader.read()) != -1) {
				// 对于windows下，\r\n这两个字符在一起时，表示一个换行。
				// 但如果这两个字符分开显示时，会换两次行。
				// 因此，屏蔽掉\r，或者屏蔽\n。否则，将会多出很多空行。
				if (((char) tempchar) != '\r') {
					System.out.print((char) tempchar);
				}
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			System.out.println("以字符为单位读取文件内容，一次读多个字节：");
			// 一次读多个字符
			char[] tempchars = new char[30];
			int charread = 0;
			reader = new InputStreamReader(new FileInputStream(fileName));
			// 读入多个字符到字符数组中，charread为一次读取字符数
			while ((charread = reader.read(tempchars)) != -1) {
				// 同样屏蔽掉\r不显示
				if ((charread == tempchars.length)
						&& (tempchars[tempchars.length - 1] != '\r')) {
					System.out.print(tempchars);
				} else {
					for (int i = 0; i < charread; i++) {
						if (tempchars[i] == '\r') {
							continue;
						} else {
							System.out.print(tempchars[i]);
						}
					}
				}
			}

		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	/**
	 * 以行为单位读取文件，常用于读面向行的格式化文件
	 */
	public static void readFileByLines(String fileName) {
		File file = new File(fileName);
		BufferedReader reader = null;
		try {
			System.out.println("以行为单位读取文件内容，一次读一整行：");
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			// 一次读入一行，直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				System.out.println("line " + line + ": " + tempString);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	/**
	 * 随机读取文件内容
	 */
	public static void readFileByRandomAccess(String fileName) {
		RandomAccessFile randomFile = null;
		try {
			System.out.println("随机读取一段文件内容：");
			// 打开一个随机访问文件流，按只读方式
			randomFile = new RandomAccessFile(fileName, "r");
			// 文件长度，字节数
			long fileLength = randomFile.length();
			// 读文件的起始位置
			int beginIndex = (fileLength > 4) ? 4 : 0;
			// 将读文件的开始位置移到beginIndex位置。
			randomFile.seek(beginIndex);
			byte[] bytes = new byte[10];
			int byteread = 0;
			// 一次读10个字节，如果文件内容不足10个字节，则读剩下的字节。
			// 将一次读取的字节数赋给byteread
			while ((byteread = randomFile.read(bytes)) != -1) {
				System.out.write(bytes, 0, byteread);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (randomFile != null) {
				try {
					randomFile.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	/**
	 * 显示输入流中还剩的字节数
	 */
	private static void showAvailableBytes(InputStream in) {
		try {
			System.out.println("当前字节输入流中的字节数为:" + in.available());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Java代码实现MySQL数据库导出
	 * 
	 * @author GaoHuanjie
	 * @param hostIP
	 *            MySQL数据库所在服务器地址IP
	 * @param userName
	 *            进入数据库所需要的用户名
	 * @param userName
	 *            进入数据库所需要的用户名
	 * @param password
	 *            进入数据库所需要的密码
	 * @param savePath
	 *            数据库导出文件保存路径
	 * @param fileName
	 *            数据库导出文件文件名
	 * @param databaseName
	 *            要导出的数据库名
	 * @return 返回true表示导出成功，否则返回false。
	 */
	public static boolean exportDatabaseTool(String hostIP, String userName,
			String password, String savePath, String fileName,
			String databaseName) throws InterruptedException {
		File saveFile = new File(savePath);
		if (!saveFile.exists()) {// 如果目录不存在
			saveFile.mkdirs();// 创建文件夹
		}
		if (!savePath.endsWith(File.separator)) {
			savePath = savePath + File.separator;
		}

		PrintWriter printWriter = null;
		BufferedReader bufferedReader = null;
		try {
			printWriter = new PrintWriter(new OutputStreamWriter(
					new FileOutputStream(savePath + fileName), "utf8"));

			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.append(Config.STRING_MYSQL_DUMP_PATH + "mysqldump")
					.append(" --opt").append(" -h").append(hostIP);
			stringBuilder.append(" --user=").append(userName)
					.append(" --password=").append(password)
					.append(" --lock-all-tables=true");
			stringBuilder.append(" --result-file=").append(savePath + fileName)
					.append(" --default-character-set=utf8 ")
					.append(databaseName);

			Process process = Runtime.getRuntime().exec(
					stringBuilder.toString());
			/*
			 * InputStream in = process.getInputStream(); InputStreamReader
			 * inputStreamReader = new InputStreamReader(in, "utf8");
			 * bufferedReader = new BufferedReader(inputStreamReader); String
			 * line; while ((line = bufferedReader.readLine()) != null) {
			 * printWriter.println(line); }
			 */

			if (process.waitFor() == 0) {// 0 表示线程正常终止。
				printWriter.flush();
				return true;
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (bufferedReader != null) {
					bufferedReader.close();
				}
				if (printWriter != null) {
					printWriter.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return false;
	}

	/**
	 * 导入
	 *
	 */
	public static boolean load(String fPath) {
		try {
			// String fPath = "e:/mysql-5.0.27-win32/bin/bjse22.sql";
			Runtime rt = Runtime.getRuntime();
			// 调用 mysql 的 cmd:
			String cmd = String.format(Config.STRING_MYSQL_DUMP_PATH + "mysql "
					+ Config.STRING_MYSQL_LINKER, Config.STRING_MYSQL_NAME,
					Config.STRING_MYSQL_PWD, Config.STRING_MYSQL_DB);
			Process child = rt.exec(cmd);
			OutputStream out = child.getOutputStream();// 控制台的输入信息作为输出流
			String inStr;
			StringBuffer sb = new StringBuffer("");
			String outStr;
			BufferedReader br = new BufferedReader(new InputStreamReader(
					new FileInputStream(fPath), "utf8"));
			while ((inStr = br.readLine()) != null) {
				sb.append(inStr + "\r\n");
			}
			outStr = sb.toString();
			OutputStreamWriter writer = new OutputStreamWriter(out, "utf-8");
			writer.write(outStr);
			// 注：这里如果用缓冲方式写入文件的话，会导致中文乱码，用flush()方法则可以避免
			writer.flush();
			// 别忘记关闭输入输出流
			out.close();
			br.close();
			writer.close();

			System.out.println("/* Load OK! */");

			return true;

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("/* Load false! */");
		return false;
	}

	/**
	 * Poi写Excel
	 * 
	 * @author csz
	 * 
	 */
	public static void PoiWriteExcel() throws IOException {
		// 创建工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 创建工作表
		HSSFSheet sheet = workbook.createSheet("sheet1");

		for (int row = 0; row < 10; row++) {
			HSSFRow rows = sheet.createRow(row);
			for (int col = 0; col < 10; col++) {
				// 向工作表中添加数据
				rows.createCell(col).setCellValue("data" + row + col);
			}
		}

		File xlsFile = new File("poi.xls");
		FileOutputStream xlsStream = new FileOutputStream(xlsFile);
		workbook.write(xlsStream);
	}

	/**
	 * Poi读Excel
	 * 
	 * @author csz
	 * 
	 */
	public static Map PoiReadFromeExcel(String name) throws IOException,
			InvalidFormatException {
		name = name.substring(name.lastIndexOf("/") + 1);
		// 获取文件存储路径
		String path = System.getProperty("hengfengapp.root")
				+ "upload/files/";
		name = path + name;
		// File xlsFile = new File("poi.xls");
		File xlsFile = new File(name);
		// 获得工作簿
		Workbook workbook = null;
		Map resultMap = new HashMap();
		List result = new ArrayList();
		String title = "";
		if (xlsFile != null) {
			try {
				workbook = WorkbookFactory.create(xlsFile);
				// 获得工作表个数
				int sheetCount = workbook.getNumberOfSheets();

				// 遍历工作表
				List names = new ArrayList();
				for (int i = 0; i < sheetCount; i++) {
					Sheet sheet = workbook.getSheetAt(i);
					// 获得行数
					int rows = sheet.getLastRowNum() + 1;
					// 获得列数，先获得一行，在得到改行列数
					Row tmp = sheet.getRow(0);
					if (tmp == null) {
						continue;
					}
					int cols = tmp.getPhysicalNumberOfCells();
					// 读取数据

					Map map = null;
					for (int row = 0; row < rows; row++) {
						if (row != 0) {

							Row r = sheet.getRow(row);
							if (!isRowEmpty(r)) {
								map = new HashMap();
								for (int col = 0; col < cols; col++) {
									if (row == 1 && i == 0) {
										names.add(getJavaValue(r.getCell(col)));
										System.out.println(getJavaValue(r
												.getCell(col)));
									} else {
										if (row != 1) {

											if (col < names.size()) {
												if (r != null
														&& r.getCell(col) != null) {
													map.put(names.get(col),
															getJavaValue(r
																	.getCell(col)));
												}
											} else {
												System.out
														.println("导入失败，文件格式不正确!");
												return null;
											}

										}
									}
								}
								if (row != 1 && map != null) {
									result.add(map);
								}

							}

						} else {
							Row r = sheet.getRow(row);
							title = getJavaValue(r.getCell(0)).toString();
							System.out.println(title);
						}

					}
				}

				resultMap.put("title", title);
				resultMap.put("data", result);

				return resultMap;
			} catch (
					EncryptedDocumentException
					| org.apache.poi.openxml4j.exceptions.InvalidFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return resultMap;

	}

	public static boolean isRowEmpty(Row row) {
		for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
			Cell cell = row.getCell(c);
			if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK)
				return false;
		}
		return true;
	}

	/**
	 * 根据不同情况获取Java类型值
	 * <ul>
	 * <li>空白类型
	 * <ul>
	 * <li>返回空字符串</li>
	 * </ul>
	 * </li>
	 * </ul>
	 * <ul>
	 * <li>布尔类型</li>
	 * <ul>
	 * <li>返回Boulean类型值</li>
	 * </ul>
	 * </ul>
	 * <ul>
	 * <li>错误类型</li>
	 * <ul>
	 * <li>返回String类型值：Bad value</li>
	 * </ul>
	 * </ul>
	 * <ul>
	 * <li>数字类型</li>
	 * <ul>
	 * <li>日期类型</li>
	 * <ul>
	 * <li>返回格式化后的String类型，e.g.2017-03-15 22:22:22</li>
	 * </ul>
	 * <li>数字类型</li>
	 * <ul>
	 * <li>返回经过处理的java中的数字字符串，e.g.1.23E3==>1230</li>
	 * </ul>
	 * </ul> </ul>
	 * <ul>
	 * <li>公式类型</li>
	 * <ul>
	 * <li>公式正常</li>
	 * <ul>
	 * <li>返回计算后的String类型结果</li>
	 * </ul>
	 * </ul>
	 * <ul>
	 * <li>公式异常</li>
	 * <ul>
	 * <li>返回错误码，e.g.#DIV/0!；#NAME?；#VALUE!</li>
	 * </ul>
	 * </ul> </ul>
	 * <ul>
	 * <li>字符串类型</li>
	 * <ul>
	 * <li>返回String类型值</li>
	 * </ul>
	 * </ul>
	 * 
	 * @param cell
	 *            XSSFCell类型单元格
	 * @return 返回Object类型值
	 * @since 2017-03-26 00:05:36{@link #getValueOfNumericCell()}
	 */
	public static Object getJavaValue(Cell cell) {
		Object o = "";
		if (cell != null) {
			int cellType = cell.getCellType();
			switch (cellType) {
			case XSSFCell.CELL_TYPE_BLANK:
				o = "";
				break;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				o = cell.getBooleanCellValue();
				break;
			case XSSFCell.CELL_TYPE_ERROR:
				o = "Bad value!";
				break;
			case XSSFCell.CELL_TYPE_NUMERIC:
				o = getValueOfNumericCell(cell);
				break;
			case XSSFCell.CELL_TYPE_FORMULA:
				try {
					o = getValueOfNumericCell(cell);
				} catch (IllegalStateException e) {
					try {
						o = cell.getRichStringCellValue().toString();
					} catch (IllegalStateException e2) {
						o = cell.getErrorCellValue();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			default:
				o = cell.getRichStringCellValue().getString();
			}

			return o;
		}

		return o;
	}

	// 获取数字类型的cell值
	private static Object getValueOfNumericCell(Cell cell) {
		Boolean isDate = DateUtil.isCellDateFormatted(cell);
		Double d = cell.getNumericCellValue();
		Object o = null;
		if (isDate) {
			o = DateFormat.getDateTimeInstance()
					.format(cell.getDateCellValue());
		} else {
			o = getRealStringValueOfDouble(d);
		}
		return o;
	}

	// 处理科学计数法与普通计数法的字符串显示，尽最大努力保持精度
	private static String getRealStringValueOfDouble(Double d) {
		String doubleStr = d.toString();
		boolean b = doubleStr.contains("E");
		int indexOfPoint = doubleStr.indexOf('.');
		if (b) {
			int indexOfE = doubleStr.indexOf('E');
			// 小数部分
			BigInteger xs = new BigInteger(doubleStr.substring(indexOfPoint
					+ BigInteger.ONE.intValue(), indexOfE));
			// 指数
			int pow = Integer.valueOf(doubleStr.substring(indexOfE
					+ BigInteger.ONE.intValue()));
			int xsLen = xs.toByteArray().length;
			int scale = xsLen - pow > 0 ? xsLen - pow : 0;
			doubleStr = String.format("%." + scale + "f", d);
		} else {
			java.util.regex.Pattern p = Pattern.compile(".0$");
			java.util.regex.Matcher m = p.matcher(doubleStr);
			if (m.find()) {
				doubleStr = doubleStr.replace(".0", "");
			}
		}
		return doubleStr;
	}

	public static File getSimpolDataExcel(List<Map<String, Object>> data,
			String name) {
		// 创建Excel工作簿对象，对应一个Excel文件
		HSSFWorkbook book = new HSSFWorkbook();
		// 创建Excel工作表对象
		HSSFSheet sheet = book.createSheet(name);
		sheet.setVerticallyCenter(true);
		int index = 0;

		// 创建单元格，并设置值表头 设置表头居中
		HSSFCellStyle styleMain = book.createCellStyle();
		// 水平居中
		styleMain.setAlignment(HorizontalAlignment.CENTER);
		// 垂直居中
		styleMain.setVerticalAlignment(VerticalAlignment.CENTER);

		for (Map<String, Object> map : data) {
			int cellNum = 0;
			// 创建Excel工作表行
			HSSFRow row = sheet.createRow(index);
			// 设置行高 单位像素
			row.setHeight((short) 400);
			// 创建单元格，并设置值表头 设置表头居中
			HSSFCellStyle styleTitle = book.createCellStyle();
			// 水平居中
			styleTitle.setAlignment(HorizontalAlignment.CENTER);
			// 垂直居中
			styleTitle.setVerticalAlignment(VerticalAlignment.CENTER);
			// 设置背景色
			styleTitle.setFillForegroundColor(IndexedColors.TEAL.getIndex());
			styleTitle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

			styleTitle.setBorderBottom(BorderStyle.THIN);
			styleTitle.setBorderLeft(BorderStyle.THIN);
			styleTitle.setBorderRight(BorderStyle.THIN);
			styleTitle.setBorderTop(BorderStyle.THIN);
			if (index == 0) {
				int i = 0;
				for (Map.Entry<String, Object> entry : map.entrySet()) {
					// 设置列的宽度 单位像素
					sheet.setColumnWidth(i++, 6000);
					// 创建Excel单元格
					HSSFCell cell = row.createCell(cellNum);
					// 设置Excel单元格值
					cell.setCellValue(entry.getKey() == null ? "--" : entry
							.getKey().toString());
					cell.setCellStyle(styleTitle);
					cellNum++;
				}
			} else {

				for (Map.Entry<String, Object> entry : map.entrySet()) {
					HSSFCell cell = row.createCell(cellNum);
					cell.setCellValue(entry.getValue() == null ? "--" : entry
							.getValue().toString());
					cell.setCellStyle(styleMain);
					cellNum++;
				}
			}
			index++;
		}
		// 设置生成的文件临时存放目录
		File dir = new File("temp/userfb");
		if (!dir.exists()) {
			dir.mkdirs();
		}
		String fileName = ("temp/userfb") + File.separator + name + ".xls";
		File file = new File(fileName);
		try {
			FileOutputStream fos = new FileOutputStream(file);
			book.write(fos);
			fos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return file;
	}

	/*
	 * public static void main(String[] args) { String fileName =
	 * "C:/Users/Administrator/Desktop/json.txt";
	 * FileUtil.readFileByBytes(fileName); //
	 * FileUtil.readFileByChars(fileName); //
	 * FileUtil.readFileByLines(fileName); //
	 * FileUtil.readFileByRandomAccess(fileName); }
	 */

	/*
	 * public static void main(String[] args) { try { if
	 * (exportDatabaseTool(Config.STRING_MYSQL_HOST, Config.STRING_MYSQL_NAME,
	 * Config.STRING_MYSQL_PWD, Config.STRING_MYSQL_PATH, "2014-10-14.sql",
	 * Config.STRING_MYSQL_DB)) { System.out.println("数据库成功备份！！！"); } else {
	 * System.out.println("数据库备份失败！！！"); } } catch (InterruptedException e) {
	 * e.printStackTrace(); } }
	 */
	public static void main(String[] args) {
		// load("D:/backupDatabase/2017-09-10-09-53-17.sql");

		/*
		 * try { PoiWriteExcel(); PoiReadFromeExcel(); } catch (IOException e) {
		 * // TODO Auto-generated catch block e.printStackTrace(); }
		 */
		List ll = new ArrayList();
		for (int i = 0; i < 100; i++) {
			Map m = new HashMap();
			for (int j = 0; j < 50; j++) {
				m.put("data" + i + "" + j, "数据" + j);
			}

			ll.add(m);
		}

		getSimpolDataExcel(ll, "数据测试");

	}

}
